package com.mc.moring.core

import android.app.Activity
import android.app.Application
import android.content.Context
import android.os.Bundle
import com.mc.moring.R
import com.mc.moring.base.BaseApplication
import com.mc.moring.util.DeviceUtils
import com.mc.moring.util.ext.StringExt.extString

object CoreConfig {

    val App_id by lazy { getAppContext().packageName }
    val App_name by lazy { getAppContext().extString(R.string.app_name) }
    val App_version by lazy { DeviceUtils.getAppVersion() }
    const val CountryCode = "56"

    private val activityList = mutableListOf<Activity>()


    var isShowVipHint = true
    var isShowGuideToHome = true
    var isShowGuideToApply = true
    var showScoreId:String?=null


    private var context: Context? = null

    fun setAppContext(context: Context) {
        this.context = context
    }

    fun getAppContext(): Context {
        return context!!
    }

    fun register(appApplication: BaseApplication){
        appApplication.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks{
            override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
                activityList.add(activity)
            }

            override fun onActivityStarted(activity: Activity) {
            }

            override fun onActivityResumed(activity: Activity) {
            }

            override fun onActivityPaused(activity: Activity) {
            }

            override fun onActivityStopped(activity: Activity) {
            }

            override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
            }

            override fun onActivityDestroyed(activity: Activity) {
                activityList.remove(activity)
            }
        })
    }

    fun getCurrentActivity():Activity?{
        return activityList.lastOrNull()
    }

}